import {createOrder} from "api/orderApi";
import { takeWine } from 'api/drinkApi.js'; 

export default {
    state: () => ({
        order: null,
        vipPriceSavingMoney: 0,
        orderTotalAmount: 0,
        orderCurrentTotalAmount: 0,
        orderPayment: 'weixin',
				// orderPayment: 'goldcoinsmoney',
				
				displacesCardId:null
				
    }),
    getters: {
        order: state => state.order,
        vipPriceSavingMoney: state => state.vipPriceSavingMoney,
        orderTotalAmount: state => state.orderTotalAmount,
        orderCurrentTotalAmount: state => state.orderCurrentTotalAmount,
        orderPayment: state => state.orderPayment,
				displacesCardId:state => state.displacesCardId
    },
    mutations: {
        setOrder(state, order = {}) {
            state.order = order
        },
        setVipPriceSavingMoney(state, money) {
            state.vipPriceSavingMoney = money
        },
        setOrderTotalAmount(state, totalAmount = 0) {
            state.orderTotalAmount = totalAmount
        },
        setOrderCurrentTotalAmount(state, totalAmount = 0) {
            state.orderCurrentTotalAmount = totalAmount
        },
        setOrderPayment(state, payment = 'weixin') {
            state.orderPayment = payment
        },
				setDisplacesCardId(state, displacesCardId = null){
					state.displacesCardId = displacesCardId
				}
    },
    actions: {
        async updateVipPriceSavingMoney({ commit }, money = 0) {
            commit('setVipPriceSavingMoney', money.toFixed(2))
        },
        async updateOrderTotalAmount({ commit }, totalAmount = 0) {
            commit('setOrderTotalAmount', totalAmount)
        },
        async updateOrderCurrentTotalAmount({ commit }, totalAmount = 0) {
            commit('setOrderCurrentTotalAmount', totalAmount)
        },
        async createNewOrder({ commit }, form) {
            const order = await createOrder(form)
            commit('setOrder', order)
        },
		async createDrinkOrder({ commit }, form) {
		    const order = await takeWine(form)
		    commit('setOrder', order)
		},
        async updateOrderPayment({ commit }, payment = 'weixin') {
            commit('setOrderPayment', payment)
        }
    }
}
